<template>
  <el-dialog :visible.sync="visible" width="70%" custom-class="default-dialog"
    :close-on-click-modal="false" @close="cancel" append-to-body>
    <div slot="title">
      <img v-if="type" :src="require(`@/assets/img/${type}.png`)" alt="">
      <span>{{ title }} </span>
    </div>
    <el-form :model="form" ref="form" label-width="100px">
      <el-form-item label="用户名：" prop="name">
        <div>{{ form.userName }}</div>
      </el-form-item>
      <el-form-item label="服务器地址：" prop="name">
        <div>{{ form.host }}</div>
      </el-form-item>
      <el-form-item label="url地址：" prop="name">
        <div>{{ form.url }}</div>
      </el-form-item>
      <el-form-item label="类型：" prop="name">
        <div>{{ form.level }}</div>
      </el-form-item>
      <el-form-item label="请求方式：" prop="name">
        <div>{{ form.method }}</div>
      </el-form-item>
      <el-form-item label="客户端浏览器内容：" prop="name">
        <div>{{ form.userAgent }}</div>
      </el-form-item>
      <el-form-item label="堆栈追踪：" prop="name">
        <json-viewer
          v-if="form.stackTrace"
          class="code-pre"
          :value="JSON.parse(form.stackTrace)"
          :expand-depth="0"
          copyable
          @copied="copys"
        >
        <template slot="copy">
          <i class="el-icon-document-copy" title="复制"></i>
        </template>
        </json-viewer>
      </el-form-item>
      <el-form-item label="请求参数：" prop="name">
        <json-viewer
          v-if="form.parameter"
          class="code-pre"
          :value="JSON.parse(form.parameter)"
          copyable
          @copied="copys"
        >
        <template slot="copy">
          <i class="el-icon-document-copy" title="复制"></i>
        </template>
        </json-viewer>
      </el-form-item>
      <el-form-item label="IP地址：" prop="name">
        <div>{{ form.ipAddress }}</div>
      </el-form-item>
      <el-form-item label="描述：" prop="name">
        <div>{{ form.message }}</div>
        <!-- <json-viewer
          v-if="form.message"
          class="code-pre"
          :value="form.message"
        >
        </json-viewer> -->
      </el-form-item>
    </el-form>
    <span slot="footer">
      <el-button size="small" @click="cancel">取 消</el-button>
      <el-button size="small" type="primary" @click="sure">确 定</el-button>
    </span>
  </el-dialog>
</template>
<script>
export default {
  data() {
    return {
      visible: false,
      title: '详情',
      form: {},
      type: 'view'
    };
  },
  methods: {
    showModal(row) {
      this.visible = true
      this.title = '详情'
      this.form = Object.assign({},row)
    },
    // 复制
    copys(){
      this.$message.success('复制成功！')
    },
    sure() {
      this.visible = false;
      this.$refs['form'].validate(valid => {
        if (valid) {
        }
      });
    },
    cancel() {
      this.visible = false;
      this.$refs["form"].resetFields();
    },
  }
};
</script>
<style lang="less" scoped>
.code-pre{
  background: rgba(0,0,0,.1);
  overflow: hidden;
}
</style>
<style lang="less">
.jv-container .jv-code{
  padding: 8px 15px!important;
}
</style>
